package org.ucas.faker.web.utils.mql.domain;

import java.util.ArrayList;
import java.util.List;

public class Select extends Query {

  private List<Field> fields = new ArrayList<>();
  private List<Order> orderBys = new ArrayList<>();
  private int offset = 0;
  private int rowCount = -1;

  private boolean selectAll = false;
  public boolean isQuery = false;

  public Select() {
  }

  public List<Field> getFields() {
    return fields;
  }

  public void setOffset(int offset) {
    this.offset = offset;
  }

  public void setRowCount(int rowCount) {
    this.rowCount = rowCount;
  }

  public int getOffset() {
    return offset;
  }

  public int getRowCount() {
    return rowCount;
  }

  public void addOrderBy(String name, String type) {
    this.orderBys.add(new Order(name, type));
  }

  public void addOrderBy(Order order) {this.orderBys.add(order);}

  public List<Order> getOrderBys() {
    return orderBys;
  }

  public void addField(Field field) {
    if (field == null) {
      return;
    }
    if (field.getName().equals("*")) {
      this.selectAll = true;
    }

    fields.add(field);
  }

  public boolean isOrderdSelect() {
    return this.getOrderBys() != null && this.getOrderBys().size() > 0;
  }

  public boolean isSelectAll() {
    return selectAll;
  }

}
